package com.gmall.product.config;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OssConfig {
    /**
     * oss:
     *   endpoint: http://oss-cn-beijing.aliyuncs.com
     *   accessKeyId: QwGbUg5VOOk5kttE
     *   accessKeySecret: o49ZIyI02MoBwjU4yEwBrLfDg0RARG
     *   hostName: https://yjs-2004a.oss-cn-beijing.aliyuncs.com/
     *   bucket: yjs-2203a
     */
    //String endpoint = "https://oss-cn-beijing.aliyuncs.com";

    // 区域
    @Value("${aliyun.oss.endpoint}")
    private String endpoint;

    // 桶名称
    @Value("${aliyun.oss.bucketName}")
    private String bucketName;

    // key
    @Value("${aliyun.oss.accessKeyId}")
    private String accessKeyId;

    // 密钥
    @Value("${aliyun.oss.accessKeySecret}")
    private String accessKeySecret;

    @Bean
    public OSS ossClientBuilder(){
        OSS ossClientBuilder = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        return ossClientBuilder;
    }
}
